﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CoverageTestTechnology.Report
{
    [Serializable]
    public class DiffItem
    {
        public HashSet<BlockItem> AddedBlocks { set; get; }
        public HashSet<BlockItem> ReducedBlocks { set; get; }

        public DiffItem() 
        {
            AddedBlocks = new HashSet<BlockItem>();
            ReducedBlocks = new HashSet<BlockItem>();
        }

        public HashSet<string> GetCoveredCasesForReducedBlocks()
        {
            HashSet<string> coveredCases = new HashSet<string>();
            if (ReducedBlocks != null)
            {
                foreach (BlockItem bi in ReducedBlocks)
                {
                    coveredCases.UnionWith(bi.CoveredCases);
                }
            }           
            return coveredCases;
        }

        public string GetCoveredCasesSummaryForReducedBlocks()
        {
            HashSet<string> coveredCases = GetCoveredCasesForReducedBlocks();
            StringBuilder sb = new StringBuilder();
            foreach (string coveredCase in coveredCases)
            {
                sb.Append(coveredCase).Append(";");
            }
            return sb.ToString().Trim(';');
        }
    }
}
